package com.example.demo.Controller;

import com.example.demo.core.NotFoundException;
import com.example.demo.core.Response;
import com.example.demo.core.security.UnauthorizedException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.ShiroException;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobalExceptionHandler {
    @ResponseStatus(value = HttpStatus.OK)
    @ExceptionHandler(NotFoundException.class)
    public Object globalExceptionHandler(NotFoundException e)
    {
        return Response.fail(401,e.getMessage());
    }

    @ResponseStatus(value = HttpStatus.OK)
    @ExceptionHandler(Exception.class)
    public Object globalExceptionHandler(Exception e)
    {
        return Response.fail(401,e.getMessage());
    }
}

